package org.csu.mypetstore.persistence;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.bouncycastle.crypto.agreement.srp.SRP6Client;
import org.csu.mypetstore.domain.User;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper {
     @Select("select * from user where username = #{username}")
     User findUserByUsername(String username);

     @Update("        update user set\n" +
             "        password=#{password},\n" +
             "        firstname=#{firstname},\n" +
             "        lastname=#{lastname},\n" +
             "        email=#{email},\n" +
             "        phone=#{phone},\n" +
             "        address1=#{address1},\n" +
             "        address2=#{address2},\n" +
             "        city=#{city},\n" +
             "        state=#{state},\n" +
             "        zip=#{zip},\n" +
             "        country=#{country},\n" +
             "        languagepre=#{languagepre},\n" +
             "        favoritecata=#{favoritecata},\n" +
             "        iflist=#{iflist},\n" +
             "        ifbanner=#{ifbanner}\n" +
             "        where username = #{username}")
     boolean updateUserByUsername(User user);

     @Select("select * from user where username = #{username} and password = #{password} and manager = 1")
     User findUserByUsernameAndPassword(User user);

     @Insert("insert into user (username,password,firstname,lastname,email,phone,address1,address2,city,state,zip,country,languagepre,manager)\n" +
             "                    values (#{username},#{password},#{firstname},#{lastname},#{email},#{phone},#{address1},#{address2},#{city},#{state},#{zip},#{country},#{languagepre},1)")
     boolean insertUserByUsernameAndPassword(User user);

     @Select("select * from user")
     List <User> getAllUser();

     @Update("        update user set\n" +
             "            password=#{password}\n" +
             "        where username = #{username}")
     boolean resetPassword(String username,String password);

     @Select("select * from user where username = #{username}")
     User showUsers(String username);

     @Delete("delete from user where username = #{username}")
     boolean remove(String username);

     @Update("        update user set\n" +
             "                        password=#{password},\n" +
             "                        firstname=#{firstname},\n" +
             "                        lastname=#{lastname},\n" +
             "                        email=#{email},\n" +
             "                        phone=#{phone}\n" +
             "        where username = #{username}")
     boolean saveUser(String username,String password,String firstname,String lastname,String phone,String email);
}
